// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.jasmin.unit.z80.v1;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class Z80v2 {
  public boolean RESET;
  
  final Controller controller = new Controller();
  final Regs regs = new Regs();
  
  int data;
  int addr;
  
  int accReg;
  int tmpReg;
  int accTmpReg;
  int flagsReg;
  int flagsTmpReg;
  
  public void updateSeq() {
    regs.RESET = RESET;
    regs.WR = controller.REGS_WRITE;
    regs.MODE_IN = controller.REGS_WRITE_MODE;
    regs.REG_IN = controller.REGS_WRITE_SELECT;
    regs.updateSeq();
  }
  
  public void updateComb() {
    switch (controller.DATA_MUX) {
      case Controller.DATA_MUX_NONE:
        data = 0;
        break;
      case Controller.DATA_MUX_REGS:
        regs.MODE_OUT = controller.REGS_READ_MODE;
        regs.REG_OUT = controller.REGS_READ_SELECT;
        regs.updateComb();
        data = regs.DATA_OUT;
        break;
      case Controller.DATA_MUX_ACC:
        data = accReg;
        break;
      case Controller.DATA_MUX_TMP:
        data = tmpReg;
        break;
    }   
  }
}
